import networkx as nx
import matplotlib.pyplot as plt

with open('generate.txt', 'r') as file:
    lines = file.readlines()
n = int(lines[0])
nodes = [int(line) for line in lines[1:n+1]]
G = nx.Graph()
G.add_nodes_from(nodes)
m = int(lines[n+1])
for line in lines[n+2:]:
    start, end, weight = map(int, line.split())
    G.add_edge(start, end, weight=weight)
fig, ax = plt.subplots()
pos = nx.spring_layout(G, seed=41) 
nx.draw(G, pos, ax=ax, with_labels=True, node_color='red', node_size=300, font_size=8, alpha=1)
edge_labels = nx.get_edge_attributes(G, 'weight')
nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels, font_size=6)
plt.title("Network Topology")
plt.show()